% This file is used to define the Global variables, initial conditions and call the required files.
% The variables are:
% p: represents zeta : wave height
% q : represents phi : surface velocity potential
% 2-D case .. in X direction


%--- main parameters
%clear all;

global Ux Uy  h  g  p  q tmax Lx Ly dx dy L Nx Ny y;
%----- Physical Parameters----------

Ux = 1; % Current Velocity in the X direction. Assumed Constant
Uy=  1;  % Current velocity in the Y direction
h = 50; % height of the bed, assumed constant
g=  9.81; % Gravitational Constant
 

%------------ Simulation Parameters % -----------------
tmax = 50;     % max time, s
Lx=  100;         % Length in the X direction
Ly =100;            % Length in the Y direction
Nx = 20;         % number of axial nodes in the X direction 
Ny=20;          % Number of Nodes in the Y direction
steps_x = Nx-1;    % number of axial steps
steps_y = Ny-1;
dx = Lx/steps_x;   % axial step spacing, delta x
dy = Ly/steps_y;

% Check the CFL condition:
dt1 = 0.5*dx/sqrt(g*h);
%--- Initial Conditions ----------
pi1=1;
qi=1;
r=zeros(Nx*Ny,1);
p_matlab=r;
for j=1:Nx
    for i=1:Ny
        index = (j-1)*Ny+i;
        p(index,1) = pi1*cos(4*pi*(j-1)*dx/Lx);
        r(i,j) = p(index);
        q(index,1) = qi;
        r(index)=0;
    end
end


% Run the matlab based Codes
i=1;
Complete_Matlab(2);
A(1:Nx*Ny,1)=y(end,1:Nx*Ny);
B(1:Nx*Ny,1)=y(end,Nx*Ny+1:2*Nx*Ny);
%C(1:Nx*Ny,1)=y(end,2*Nx*Ny+1:3*Nx*Ny);

for j=1:Nx
    for i=1:Ny
        index = (j-1)*Ny+i;
        p_matlab(i,j) = A(index);
    end
end
surf(r)
hold on

dt =1.0;

    TimeDiscretizers(dt,1);
    A(1:Nx*Ny,2)=p;
    B(1:Nx*Ny,2)=q;
%     X = sprintf('The Norm of the Error for Zeta is %f' , norm_L2(A(:,1),A(:,i+1)));
%     disp(X);
%     X = sprintf('The Norm of the Error for varphi is %f' ,  norm_L2(B(:,1),B(:,i+1)));
%     disp(X);

% for j=1:Nx
%     for i=1:Ny
%         index = (j-1)*Ny+i;
%         r(i,j) = p(index);
%     end
% end
% 
% 
% for k=1:3
%     for j=1:Nx
%         for i=1:Ny
%             index = (j-1)*Ny+i;
%             r(i,j,k) = A(index,k);
%         end
%     end
% end
% surf(r)